[% setvar title Symbols, symbols everywhere %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Symbols, symbols everywhere</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Paolo Molaro &lt;<a href='mailto:lupus@debian.org'>lupus@debian.org</a>&gt;
  Date: 26 Sep 2000
  Mailing List: <a href='mailto:perl6-internals@perl.org'>perl6-internals@perl.org</a>
  Number: 326
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Perl should adopt scheme-like symbols, both at the language level
and at the internals level.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Symbols can be useful in a variety of ways both at the language
level and as an implementation detail for efficiency reasons.</p>
<a name='Symbols at the language level'></a><h2>Symbols at the language level</h2>
<p>A possible operator to create a symbol could be qs// for <b>q</b>uote <b>s</b>ymbol.
A one character operator could be useful as well, but since ^ is likely
to be taken by curried expressions, an alternative could be <code>:</code>.</p>
<pre>	$symbol = qs(methodname); # or ^methodname or :methodname
	$object-&gt;$symbol;</pre>
<p>They can be also useful in XS modules to map constants more efficiently
than today's constant() function.</p>
<p>Characters following the one-char operator are limited to the usual
identifier characters. Probably, the same character used as operator
should be used in subroutines prototypes to allow for compile time
optimizations.</p>
<p>Only equal/non equal comparison operations should be allowed on symbols.</p>
<a name='Symbols in the inplementation'></a><h2>Symbols in the inplementation</h2>
<p>Symbols are &quot;interned&quot; during compilation. From then on symbols are
actually treated like numbers, so comparisons are faster. They should be
used to hold package names, method names and so on. This way symbol tables
can be implemented as optimized integer hash tables instead of string hash
tables (for packages with few methods a binary search could be also a win).
A symbol should be used anywhere a package name or method name is used now
at the API level (this applies to variable names, too).</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Should be trivial. A symbol scalar could be a read-only scalar with both
the string and integer properties set. Note that additional memory should
not be allocated for each copy of a symbol: once &quot;interned&quot; they are  never
free'd: the vtable stuff can make this very simple.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>Your preferred scheme book.</p>
<p>GLib's GQuarks and Xlib's Atoms for implementations.</p>
</div>
